//验证码刷新
function reloadcode() {
	var timenow = new Date().getTime();
	$('#_37degree_verifyImg').attr('src', '/member/verify/' + timenow);
	return;
}

// 判断是否为空
function stringIsNull(string) {
	if (!string && typeof (string) != "undefined" && string !== 0) {
		return true;
	} else {
		return false;
	}
}

// 验证邮箱格式
function checkEmail(email) {
	var pattern = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	if (!pattern.test(email)) {
		return false;
	} else {
		return true;
	}
}

// 验证正整数
function checkNum(v) {
	var pattern = /^[1-9][0-9]*$/;
	if (!pattern.test(v)) {
		return false;
	} else {
		return true;
	}
}

// 验证手机号格式
function checkMobile(mobile) {
	var pattern = /^1\d{10}$/;
	if (!pattern.test(mobile)) {
		return false;
	} else {
		return true;
	}
}

// 验证密码格式
function checkPasswd(passwd) {
	var pattern = /^[\w~!@#$%^&*]{6,16}$/;
	if (!pattern.test(passwd)) {
		return false;
	} else {
		return true;
	}
}

// 验证密码格式
function checkDomain(domain) {
	var pattern = /^[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	if (!pattern.test(domain)) {
		return false;
	} else {
		return true;
	}
}

function checkEnName(name) {
	var pattern = /^[a-zA-Z][a-zA-Z0-9_]{0,30}$/;
	if (!pattern.test(name)) {
		return false;
	} else {
		return true;
	}
}

// function gotopage(target)
// {
// cpage = target; //把页面计数定位到第几页
// setpage();
// //reloadpage(target); //调用显示页面函数显示第几页,这个功能是用在页面内容用ajax载入的情况
// }

function _37degree_setpage(cpage, totalpage) {


	// cpage 当前页数
	// totalpage 总页数

	var outstr = "";
	if(totalpage<=1) return "";
	
	outstr += '<ul style=" float:left; margin-left:37%">';
	// 总页数小于十页
	if (totalpage <= 10) {
		for (count = 1; count <= totalpage; count++) {
			if (count != cpage) {
				outstr += '<li><a href="#" onclick="gotopage(' + count + ')">'
						+ count + '</a></li>';
			} else {
				outstr += '<li><a href="#" class="hr">' + count + '</a></li>';
			}
		}
	}

	// 总页数大于十页
	if (totalpage > 10) {
		if (parseInt((cpage - 1) / 10) == 0) {// 当前页为11时
			for (count = 1; count <= 10; count++) {
				if (count != cpage) {
					outstr += '<li><a href="#" onclick="gotopage(' + count
							+ ')">' + count + '</a></li>';
				} else {
					outstr += '<li><a href="#" class="hr">' + count
							+ '</a></li>';
				}
			}

			outstr += '<li><a href="#" onclick="gotopage('
					+ eval(parseInt(cpage) + parseInt(1)) + ')">下一页</a></li>';
			outstr += '<li><a href="#" onclick="gotopage(' + count
					+ ');">&gt;</a></li>';

		} else if (parseInt((cpage - 1) / 10) == parseInt(totalpage / 10)) {
			outstr = outstr
					+ "<li><a href='javascript:void(0)' onclick='gotopage("
					+ (parseInt((cpage - 1) / 10) * 10) + ")'>&lt;</a></li>";
			outstr = outstr
					+ "<li><a href='javascript:void(0)' onclick='gotopage("
					+ parseInt(eval(cpage - 1)) + ")'>上一页</a></li>";

			for (count = parseInt(totalpage / 10) * 10 + 1; count <= totalpage; count++) {
				if (count != cpage) {
					outstr += '<li><a href="#" onclick="gotopage(' + count
							+ ')">' + count + '</a></li>';
				} else {
					outstr += '<li><a href="#" class="hr">' + count
							+ '</a></li>';
				}
			}

		} else {
			outstr = outstr
					+ "<li><a href='javascript:void(0)' onclick='gotopage("
					+ (parseInt((cpage - 1) / 10) * 10) + ")'>&lt;</a></li>";
			outstr = outstr
					+ "<li><a href='javascript:void(0)' onclick='gotopage("
					+ parseInt(eval(cpage - 1)) + ")'>上一页</a></li>";

			for (count = parseInt((cpage - 1) / 10) * 10 + 1; count <= parseInt((cpage - 1) / 10) * 10 + 10; count++) {
				if (count != cpage) {
					outstr += '<li><a href="#" onclick="gotopage(' + count
							+ ')">' + count + '</a></li>';
				} else {
					outstr += '<li><a href="#" class="hr">' + count
							+ '</a></li>';
				}
			}

			outstr += '<li><a href="#" onclick="gotopage('
					+ eval(parseInt(cpage) + parseInt(1)) + ')">下一页</a></li>';
			outstr += '<li><a href="#" onclick="gotopage(' + count
					+ ')">&gt;</a></li>';
		}

	}

	outstr += "</ul>";

	return outstr;

}

// jsonFormat(json,true)为开启压缩模式
// jsonFormat(json,false)这样为格式化代码
function jsonFormat(txt, compress) {
	var indentChar = '    ';
	if (/^\s*$/.test(txt)) {
		var tab = '    ';
		var mstring = '{\n' + tab + '"return_code":999999,\n' + tab + '"return_msg":无数据返回\n}';
		return mstring;
	}
	try {
		var data = eval('(' + txt + ')');
	} catch (e) {
		var tab = '    ';
		var mstring = '{\n' + tab + '"return_code":444444,\n' + tab + '"return_msg":数据源语法错误,格式化失败\n}';
		return mstring;
	}
	;
	var draw = [], last = false, This = this, line = compress ? '' : '\n', nodeCount = 0, maxDepth = 0;

	var notify = function(name, value, isLast, indent/* 缩进 */, formObj) {
		nodeCount++;/* 节点计数 */
		for (var i = 0, tab = ''; i < indent; i++) {
			tab += indentChar;/* 缩进HTML */
		}
		tab = compress ? '' : tab;/* 压缩模式忽略缩进 */
		maxDepth = ++indent;/* 缩进递增并记录 */
		if (value && value.constructor == Array) {/* 处理数组 */
			draw.push(tab + (formObj ? ('"' + name + '":') : '') + '[' + line);/*
																				 * 缩进'['
																				 * 然后换行
																				 */
			for (var i = 0; i < value.length; i++)
				notify(i, value[i], i == value.length - 1, indent, false);
			draw.push(tab + ']' + (isLast ? line : (',' + line)));/* 缩进']'换行,若非尾元素则添加逗号 */
		} else if (value && typeof value == 'object') {/* 处理对象 */
			draw.push(tab + (formObj ? ('"' + name + '":') : '') + '{' + line);/*
																				 * 缩进'{'
																				 * 然后换行
																				 */
			var len = 0, i = 0;
			for ( var key in value)
				len++;
			for ( var key in value)
				notify(key, value[key], ++i == len, indent, true);
			draw.push(tab + '}' + (isLast ? line : (',' + line)));/* 缩进'}'换行,若非尾元素则添加逗号 */
		} else {
			if (typeof value == 'string')
				value = '"' + value + '"';
			draw.push(tab + (formObj ? ('"' + name + '":') : '') + value
					+ (isLast ? '' : ',') + line);
		}
		;
	};
	var isLast = true, indent = 0;
	notify('', data, isLast, indent, false);
	return draw.join('');

}

// 创建具体页码链接html代码
function createPageHtml(totalpage) {

}

// 居中显示
function make_middle($layer) {
	layer_height = typeof $layer.outerHeight != 'undefined' ? $layer
			.outerHeight() : $layer.height();
	layer_width = typeof $layer.outerWidth != 'undefined' ? $layer.outerWidth()
			: $layer.width();
	var top = ($(window).height() - layer_height) / 2;
	top = top > 0 ? top : 0;
	var left = ($(window).width() - layer_width) / 2;
	left = left > 0 ? left : 0;
	$layer.css({
		'top' : top + 'px',
		'left' : left + 'px'
	});
}

// 弹窗方法
function show_msg(settings) {
	var default_settings = {
		title : '',
		msg : '', // 提示信息
		time : 1000, // 传false或0为不自动关闭
		type : 'warning', // 提示类型ok/warning/error
		modal : false, // 是否模态
		close_btn : false
	// 是否显示关闭按钮
	};
	settings = $.extend({}, default_settings, settings);
	var icon = '';
	switch (settings.type) {
	case 'ok':
		icon = '1';
		break;
	case 'warning':
		icon = '2';
		break;
	case 'error':
		icon = '2';
		break;
	default:
		icon = '1';
	}
	var $msg_layer = $('<div id="yes" class="popup" ><div class="wronginfo list_border_'
			+ icon
			+ ' wronginfo_background">\
            <h3 class="icon fl">\
                <p class="txt">'
			+ settings.msg
			+ '</p>\
                </h3><div class="cls"></div>\
        </div></div>');

	$('body').append($msg_layer);
	// 居中
	make_middle($msg_layer);
	// 垂直偏上
	var top = ($(window).height() - $msg_layer.height()) / 2;
	top = (top / 2) > 0 ? (top / 2) : 0;
	$msg_layer.css({
		'top' : top + 'px'
	});

	if (typeof hide_msg !== 'undefined') {
		clearTimeout(hide_msg);
	}
	if (settings.time) {
		hide_msg = setTimeout(function() {
			$msg_layer.remove();
			hide_msg = null;
		}, settings.time ? settings.time : 2000);
	}
}

/**
 * 对日期进行格式化，
 * 
 * @param date
 *            要格式化的日期
 * @param format
 *            进行格式化的模式字符串 支持的模式字母有： y:年, M:年中的月份(1-12), d:月份中的天(1-31),
 *            h:小时(0-23), m:分(0-59), s:秒(0-59), S:毫秒(0-999), q:季度(1-4)
 * @return String
 */
function dateFormat(date, format) {
	date = new Date(date * 1000);
	var map = {
		"M" : date.getMonth() + 1, // 月份
		"d" : date.getDate(), // 日
		"h" : date.getHours(), // 小时
		"m" : date.getMinutes(), // 分
		"s" : date.getSeconds(), // 秒
		"q" : Math.floor((date.getMonth() + 3) / 3), // 季度
		"S" : date.getMilliseconds()
	// 毫秒
	};

	format = format.replace(/([yMdhmsqS])+/g, function(all, t) {
		var v = map[t];
		if (v !== undefined) {
			if (all.length > 1) {
				v = '0' + v;
				v = v.substr(v.length - 2);
			}
			return v;
		} else if (t === 'y') {
			return (date.getFullYear() + '').substr(4 - all.length);
		}
		return all;
	});
	return format;
}

/*
 * 判断图片大小
 * 
 * @param imgsrc type="file"的javascript对象 @param width 需要符合的宽 @param height
 * 需要符合的高 @return true-符合要求,false-不符合
 */
function checkImgPX(imgsrc, width, height) {
	var img = new Image();
	img.src = imgsrc;
	// alert(img.src);
//	console.log(img);
	var imgwidth = img.offsetWidth;
	var imgheight = img.height;
	// alert(imgwidth+"===="+imgheight);

	if (imgwidth > width || imgheight > height) {
		show_msg({
			msg : '图片尺寸不符合要求',
			type : 'notice'
		});
		// imgsrc.value = "";
		return false;
	}
	return true;
}
